// 综合态势
import Util from '../../Util';
import { MigrationMap } from './MigrationMap'
import { AdministrationMap } from './AdministrationMap'
import ClusterPointMap from './ClusterPointMap'
import {DistributeMap} from './DistributeMap';
const componentBase = (G as any).base.ComponentBase;

const component = componentBase.extend({
    // 属性
    options: {
        map: null,
        simpleRenderMgr: null,
        popupManager: null,
        featureLocate: null,
        featureHighlight: null,
        symbolConfig: null,
        mapConfig:null,
        highLightId: 'compresituation_sjts', // 高亮id
        popupId: 'popup_compresituation_sjts', // 弹窗唯一标识
        popupEventName: 'compresituation_popup', // 详情框事件名
        featureType: 'compresituation_sjts', // 图层标识
    },
    // 初始化
    initialize(options: any) {
        componentBase.prototype.initialize.call(this, options);
        this.migrationMap = new MigrationMap(options);
        this.adMap = new AdministrationMap(options);

        const clusterOpt: any = this.options;
        clusterOpt.map = this.map;
        this.clusterPointMap = new ClusterPointMap(clusterOpt);
        this.distributeMap = new DistributeMap(options);
    },
    //  销毁
    destroy() {
        this.migrationMap = null;
        this.clusterPointMap = null;
        componentBase.prototype.destroy.call(this);
    },

    async addMigrationMap(areaId: any, date: any, migrateType: any) {
        this.migrationMap.addMigrationMap(areaId, date, migrateType)
    },

    async addAdminMap() {
        const layer = this.adMap.addWMSLayer()
        this.map.addLayer(layer)
    },

    removeMigrationMap() {
        this.migrationMap.removeMigrationMap();
    },
    getClusterComponent() {
        return this.clusterPointMap;
    },
    /**
     * 右侧列表点击选中某类数据，将数据添加到地图上
     * @param districtCode 行政区划编码
     * @param type 图标对应的类型
     */
    addPointByType(districtCode: any, type: any) {
        // 点上图
        this.clusterPointMap._addPointByType(districtCode, type);
    },
    // 删除聚类点图层，右侧列表反选某类数据
    removePointLayer() {
        this.clusterPointMap._removePointLayer();
    },

    // 添加感染分布图
    addSickMap(districtCode: string) {
        this.distributeMap.addSickMap(districtCode);
    },

    // 移除感染分布图
    removeSickMap() {
        this.distributeMap.removeSickMap();
    },

    // 添加人口分布图
    addPopulationMap(districtCode: string) {
        this.distributeMap.addPopulationMap(districtCode);
    },

    // 移除人口分布图
    removePopulationMap() {
        this.distributeMap.removePopulationMap();
    },

    showSickMap() {
        this.distributeMap.showSickMap();
    },

    hideSickMap() {
        this.distributeMap.hideSickMap();
    },

    showPopulationMap() {
        this.distributeMap.showPopulationMap();
    },

    hidePopulationMap() {
        this.distributeMap.hidePopulationMap();
    },

    load() {
        this.clusterPointMap.load();
        componentBase.prototype.load.call(this);
    },
    addListeners() {
        // 添加事件监听，load调用时父类触发
        this.distributeMap.on('districtchange',(data: any)=> {
            this.fire('districtchange', data)
        })
    },

    unload() {
        this.clusterPointMap.unload();
        this.migrationMap.unload();
        this.distributeMap.destroy();
        componentBase.prototype.unload.call(this);
    },

    removeListeners() {
        // 移除事件监听，unload调用时父类触发
        this.distributeMap.off('districtchange')
    },

    closePopup() {
        this.clusterPointMap.closePopup();
    },

    // 调整视野
    _fit() {
        const layer: any = this.options.simpleRenderMgr.getLayer(this.options.featureType);
        const extent: any = G.utils.LayerUtil.getLayerExtent(layer);
        this.map.pan(extent, new Array(4).fill(100));
    },

});

export default component;
